package yt.spider.widget.main;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import yt.spider.R;

/**
 * Created by 小呆呆 on 2018/1/19.
 */

public class FindFragment extends Fragment {

    private WebView myWebView;
    private String myUrl= "http://www.qidian.com";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_find, null);
        myWebView = view.findViewById(R.id.webview);

        initWebView();

        return view;
    }

    private void initWebView() {
        myWebView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //系统会默认打开你所默认的浏览器去打开网址
                // 为了要网址显示在自己的webview中，必须要设置这个属性
                view.loadUrl(url);
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
        myWebView.loadUrl(myUrl);
    }
}